import Vue from 'vue'
import Router from 'vue-router'
import PageOpen from './views/PageOpen'

Vue.use(Router)

Router.prototype.goBack = function() {
  const view = document.querySelector('#app')
  view.scrollTo(0, 0)
  this.isBack = false
  window.history.go(-1)
}
Router.prototype.goTo = function(target, param) {
  const view = document.querySelector('#app')
  view.scrollTo(0, 0)
  this.isBack = true
  target.$router.push(param)
}

export default new Router({
  routes: [
    {
      path: '/',
      name: 'open',
      component: PageOpen
    },
    {
      path: '/page',
      name: 'page',
      component: () => import('@/components/LayerPage'),
      children: [
        {
          path: '/html5',
          name: 'html5',
          component: () => import('./views/PageHtml5')
        },
        {
          path: '/video',
          name: 'video',
          component: () => import('./views/PageVideo')
        },
        {
          path: '/poster',
          name: 'poster',
          component: () => import('./views/PagePoster')
        },
        {
          path: '/longImage',
          name: 'longImage',
          component: () => import('./views/PageLongImage')
        }
      ]
    },
    {
      path: '/view',
      name: 'view',
      component: () => import('./components/LayerView'),
      children: [
        {
          path: '/imageView',
          name: '/imageView',
          component: () => import('./views/PageImageView')
        },
        {
          path: '/videoView',
          name: '/videoView',
          component: () => import('./views/PageVideoView')
        },
        {
          path: '/webView',
          name: '/webView',
          component: () => import('./views/PageWebView')
        }
      ]
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    return { x: 0, y: 0 }
  }
})
